<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class UNIXSocket - socket: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="BasicSocket.html">BasicSocket</a>
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-pair">::pair</a>
    <li ><a href="#method-c-socketpair">::socketpair</a>
    <li ><a href="#method-i-addr">#addr</a>
    <li ><a href="#method-i-path">#path</a>
    <li ><a href="#method-i-peeraddr">#peeraddr</a>
    <li ><a href="#method-i-recv_io">#recv_io</a>
    <li ><a href="#method-i-recvfrom">#recvfrom</a>
    <li ><a href="#method-i-send_io">#send_io</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-UNIXSocket">
    <h1 id="class-UNIXSocket" class="class">
      class UNIXSocket
    </h1>

    <section class="description">
    
<p><a href="UNIXSocket.html"><code>UNIXSocket</code></a> represents a UNIX domain stream client socket.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(path) &rarr; unixsocket
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new UNIX client socket connected to <em>path</em>.</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;socket&#39;</span>

<span class="ruby-identifier">s</span> = <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;/tmp/sock&quot;</span>)
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">send</span> <span class="ruby-string">&quot;hello&quot;</span>, <span class="ruby-value">0</span>
</pre>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
unix_init(VALUE sock, VALUE path)
{
    return rsock_init_unixsock(sock, path, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-pair" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          pair([type [, protocol]])       &rarr; [unixsocket1, unixsocket2]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          socketpair([type [, protocol]]) &rarr; [unixsocket1, unixsocket2]
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a pair of sockets connected to each other.</p>

<p><em>type</em> should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.</p>

<p><em>protocol</em> should be a protocol defined in the domain. 0 is default protocol for the domain.</p>

<pre class="ruby"><span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span> = <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">pair</span>
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">send</span> <span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-value">0</span>
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">send</span> <span class="ruby-string">&quot;b&quot;</span>, <span class="ruby-value">0</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">recv</span>(<span class="ruby-value">10</span>) <span class="ruby-comment">#=&gt; &quot;ab&quot;</span>
</pre>

                              <div class="method-source-code" id="pair-source">
            <pre>static VALUE
unix_s_socketpair(int argc, VALUE *argv, VALUE klass)
{
    VALUE domain, type, protocol;
    VALUE args[3];

    domain = INT2FIX(PF_UNIX);
    rb_scan_args(argc, argv, &quot;02&quot;, &amp;type, &amp;protocol);
    if (argc == 0)
        type = INT2FIX(SOCK_STREAM);
    if (argc &lt;= 1)
        protocol = INT2FIX(0);

    args[0] = domain;
    args[1] = type;
    args[2] = protocol;

    return rsock_sock_s_socketpair(3, args, klass);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-socketpair" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          pair([type [, protocol]])       &rarr; [unixsocket1, unixsocket2]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          socketpair([type [, protocol]]) &rarr; [unixsocket1, unixsocket2]
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a pair of sockets connected to each other.</p>

<p><em>type</em> should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.</p>

<p><em>protocol</em> should be a protocol defined in the domain. 0 is default protocol for the domain.</p>

<pre class="ruby"><span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span> = <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">pair</span>
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">send</span> <span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-value">0</span>
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">send</span> <span class="ruby-string">&quot;b&quot;</span>, <span class="ruby-value">0</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">recv</span>(<span class="ruby-value">10</span>) <span class="ruby-comment">#=&gt; &quot;ab&quot;</span>
</pre>

                              <div class="method-source-code" id="socketpair-source">
            <pre>static VALUE
unix_s_socketpair(int argc, VALUE *argv, VALUE klass)
{
    VALUE domain, type, protocol;
    VALUE args[3];

    domain = INT2FIX(PF_UNIX);
    rb_scan_args(argc, argv, &quot;02&quot;, &amp;type, &amp;protocol);
    if (argc == 0)
        type = INT2FIX(SOCK_STREAM);
    if (argc &lt;= 1)
        protocol = INT2FIX(0);

    args[0] = domain;
    args[1] = type;
    args[2] = protocol;

    return rsock_sock_s_socketpair(3, args, klass);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-addr" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          addr &rarr; [address_family, unix_path]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the local address as an array which contains address_family and unix_path.</p>

<p>Example</p>

<pre class="ruby"><span class="ruby-identifier">serv</span> = <span class="ruby-constant">UNIXServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;/tmp/sock&quot;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">addr</span> <span class="ruby-comment">#=&gt; [&quot;AF_UNIX&quot;, &quot;/tmp/sock&quot;]</span>
</pre>

                              <div class="method-source-code" id="addr-source">
            <pre>static VALUE
unix_addr(VALUE sock)
{
    rb_io_t *fptr;
    struct sockaddr_un addr;
    socklen_t len = (socklen_t)sizeof addr;
    socklen_t len0 = len;

    GetOpenFile(sock, fptr);

    if (getsockname(fptr-&gt;fd, (struct sockaddr*)&amp;addr, &amp;len) &lt; 0)
        rsock_sys_fail_path(&quot;getsockname(2)&quot;, fptr-&gt;pathv);
    if (len0 &lt; len) len = len0;
    return rsock_unixaddr(&amp;addr, len);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-path" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          path &rarr; path
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the path of the local address of unixsocket.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-constant">UNIXServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;/tmp/sock&quot;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">path</span> <span class="ruby-comment">#=&gt; &quot;/tmp/sock&quot;</span>
</pre>

                              <div class="method-source-code" id="path-source">
            <pre>static VALUE
unix_path(VALUE sock)
{
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    if (NIL_P(fptr-&gt;pathv)) {
        struct sockaddr_un addr;
        socklen_t len = (socklen_t)sizeof(addr);
        socklen_t len0 = len;
        if (getsockname(fptr-&gt;fd, (struct sockaddr*)&amp;addr, &amp;len) &lt; 0)
            rsock_sys_fail_path(&quot;getsockname(2)&quot;, fptr-&gt;pathv);
        if (len0 &lt; len) len = len0;
        fptr-&gt;pathv = rb_obj_freeze(rsock_unixpath_str(&amp;addr, len));
    }
    return rb_str_dup(fptr-&gt;pathv);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-peeraddr" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          peeraddr &rarr; [address_family, unix_path]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the remote address as an array which contains address_family and unix_path.</p>

<p>Example</p>

<pre class="ruby"><span class="ruby-identifier">serv</span> = <span class="ruby-constant">UNIXServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;/tmp/sock&quot;</span>)
<span class="ruby-identifier">c</span> = <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;/tmp/sock&quot;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">peeraddr</span> <span class="ruby-comment">#=&gt; [&quot;AF_UNIX&quot;, &quot;/tmp/sock&quot;]</span>
</pre>

                              <div class="method-source-code" id="peeraddr-source">
            <pre>static VALUE
unix_peeraddr(VALUE sock)
{
    rb_io_t *fptr;
    struct sockaddr_un addr;
    socklen_t len = (socklen_t)sizeof addr;
    socklen_t len0 = len;

    GetOpenFile(sock, fptr);

    if (getpeername(fptr-&gt;fd, (struct sockaddr*)&amp;addr, &amp;len) &lt; 0)
        rsock_sys_fail_path(&quot;getpeername(2)&quot;, fptr-&gt;pathv);
    if (len0 &lt; len) len = len0;
    return rsock_unixaddr(&amp;addr, len);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-recv_io" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          recv_io([klass [, mode]]) &rarr; io
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Example</p>

<pre class="ruby"><span class="ruby-constant">UNIXServer</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;/tmp/sock&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">serv</span><span class="ruby-operator">|</span>
  <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;/tmp/sock&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">s</span> = <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">accept</span>

    <span class="ruby-identifier">c</span>.<span class="ruby-identifier">send_io</span> <span class="ruby-constant">STDOUT</span>
    <span class="ruby-identifier">stdout</span> = <span class="ruby-identifier">s</span>.<span class="ruby-identifier">recv_io</span>

    <span class="ruby-identifier">p</span> <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">fileno</span> <span class="ruby-comment">#=&gt; 1</span>
    <span class="ruby-identifier">p</span> <span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">fileno</span> <span class="ruby-comment">#=&gt; 7</span>

    <span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;hello&quot;</span> <span class="ruby-comment"># outputs &quot;hello\n&quot; to standard output.</span>
  }
}
</pre>

<p><em>klass</em> will determine the class of <em>io</em> returned (using the IO.for_fd singleton method or similar). If <em>klass</em> is <code>nil</code>, an integer file descriptor is returned.</p>

<p><em>mode</em> is the same as the argument passed to IO.for_fd</p>

                              <div class="method-source-code" id="recv_io-source">
            <pre>static VALUE
unix_recv_io(int argc, VALUE *argv, VALUE sock)
{
    VALUE klass, mode;
    rb_io_t *fptr;
    struct iomsg_arg arg;
    struct iovec vec[2];
    char buf[1];
    unsigned int gc_reason = 0;
    enum {
        GC_REASON_EMSGSIZE = 0x1,
        GC_REASON_TRUNCATE = 0x2,
        GC_REASON_ENOMEM = 0x4
    };

    int fd;
#if FD_PASSING_BY_MSG_CONTROL
    union {
        struct cmsghdr hdr;
        char pad[sizeof(struct cmsghdr)+8+sizeof(int)+8];
    } cmsg;
#endif

    rb_scan_args(argc, argv, &quot;02&quot;, &amp;klass, &amp;mode);
    if (argc == 0)
        klass = rb_cIO;
    if (argc &lt;= 1)
        mode = Qnil;

retry:
    GetOpenFile(sock, fptr);

    arg.msg.msg_name = NULL;
    arg.msg.msg_namelen = 0;

    vec[0].iov_base = buf;
    vec[0].iov_len = sizeof(buf);
    arg.msg.msg_iov = vec;
    arg.msg.msg_iovlen = 1;

#if FD_PASSING_BY_MSG_CONTROL
    arg.msg.msg_control = (caddr_t)&amp;cmsg;
    arg.msg.msg_controllen = (socklen_t)CMSG_SPACE(sizeof(int));
    arg.msg.msg_flags = 0;
    cmsg.hdr.cmsg_len = (socklen_t)CMSG_LEN(sizeof(int));
    cmsg.hdr.cmsg_level = SOL_SOCKET;
    cmsg.hdr.cmsg_type = SCM_RIGHTS;
    fd = -1;
    memcpy(CMSG_DATA(&amp;cmsg.hdr), &amp;fd, sizeof(int));
#else
    arg.msg.msg_accrights = (caddr_t)&amp;fd;
    arg.msg.msg_accrightslen = sizeof(fd);
    fd = -1;
#endif

    arg.fd = fptr-&gt;fd;
    while ((int)BLOCKING_REGION_FD(recvmsg_blocking, &amp;arg) == -1) {
        int e = errno;
        if (e == EMSGSIZE &amp;&amp; !(gc_reason &amp; GC_REASON_EMSGSIZE)) {
            /* FreeBSD gets here when we&#39;re out of FDs */
            gc_reason |= GC_REASON_EMSGSIZE;
            rb_gc_for_fd(EMFILE);
            goto retry;
        }
        else if (e == ENOMEM &amp;&amp; !(gc_reason &amp; GC_REASON_ENOMEM)) {
            /* ENOMEM is documented in recvmsg manpages */
            gc_reason |= GC_REASON_ENOMEM;
            rb_gc_for_fd(e);
            goto retry;
        }
        if (!rb_io_wait_readable(arg.fd))
            rsock_syserr_fail_path(e, &quot;recvmsg(2)&quot;, fptr-&gt;pathv);
    }

#if FD_PASSING_BY_MSG_CONTROL
    if (arg.msg.msg_controllen &lt; (socklen_t)sizeof(struct cmsghdr)) {
        /* FreeBSD and Linux both get here when we&#39;re out of FDs */
        if (!(gc_reason &amp; GC_REASON_TRUNCATE)) {
            gc_reason |= GC_REASON_TRUNCATE;
            rb_gc_for_fd(EMFILE);
            goto retry;
        }
        rb_raise(rb_eSocket,
                 &quot;file descriptor was not passed (msg_controllen=%d smaller than sizeof(struct cmsghdr)=%d)&quot;,
                 (int)arg.msg.msg_controllen, (int)sizeof(struct cmsghdr));
    }
    if (cmsg.hdr.cmsg_level != SOL_SOCKET) {
        rb_raise(rb_eSocket,
                 &quot;file descriptor was not passed (cmsg_level=%d, %d expected)&quot;,
                 cmsg.hdr.cmsg_level, SOL_SOCKET);
    }
    if (cmsg.hdr.cmsg_type != SCM_RIGHTS) {
        rb_raise(rb_eSocket,
                 &quot;file descriptor was not passed (cmsg_type=%d, %d expected)&quot;,
                 cmsg.hdr.cmsg_type, SCM_RIGHTS);
    }
    if (arg.msg.msg_controllen &lt; (socklen_t)CMSG_LEN(sizeof(int))) {
        rb_raise(rb_eSocket,
                 &quot;file descriptor was not passed (msg_controllen=%d smaller than CMSG_LEN(sizeof(int))=%d)&quot;,
                 (int)arg.msg.msg_controllen, (int)CMSG_LEN(sizeof(int)));
    }
    if ((socklen_t)CMSG_SPACE(sizeof(int)) &lt; arg.msg.msg_controllen) {
        rb_raise(rb_eSocket,
                 &quot;file descriptor was not passed (msg_controllen=%d bigger than CMSG_SPACE(sizeof(int))=%d)&quot;,
                 (int)arg.msg.msg_controllen, (int)CMSG_SPACE(sizeof(int)));
    }
    if (cmsg.hdr.cmsg_len != CMSG_LEN(sizeof(int))) {
        rsock_discard_cmsg_resource(&amp;arg.msg, 0);
        rb_raise(rb_eSocket,
                 &quot;file descriptor was not passed (cmsg_len=%d, %d expected)&quot;,
                 (int)cmsg.hdr.cmsg_len, (int)CMSG_LEN(sizeof(int)));
    }
#else
    if (arg.msg.msg_accrightslen != sizeof(fd)) {
        rb_raise(rb_eSocket,
                 &quot;file descriptor was not passed (accrightslen=%d, %d expected)&quot;,
                 arg.msg.msg_accrightslen, (int)sizeof(fd));
    }
#endif

#if FD_PASSING_BY_MSG_CONTROL
    memcpy(&amp;fd, CMSG_DATA(&amp;cmsg.hdr), sizeof(int));
#endif

    rb_update_max_fd(fd);
    rb_maygvl_fd_fix_cloexec(fd);

    if (klass == Qnil)
        return INT2FIX(fd);
    else {
        ID for_fd;
        int ff_argc;
        VALUE ff_argv[2];
        CONST_ID(for_fd, &quot;for_fd&quot;);
        ff_argc = mode == Qnil ? 1 : 2;
        ff_argv[0] = INT2FIX(fd);
        ff_argv[1] = mode;
        return rb_funcallv(klass, for_fd, ff_argc, ff_argv);
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-recvfrom" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          recvfrom(maxlen [, flags[, outbuf]]) &rarr; [mesg, unixaddress]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Receives a message via <em>unixsocket</em>.</p>

<p><em>maxlen</em> is the maximum number of bytes to receive.</p>

<p><em>flags</em> should be a bitwise OR of Socket::MSG_* constants.</p>

<p><em>outbuf</em> will contain only the received data after the method call even if it is not empty at the beginning.</p>

<pre class="ruby"><span class="ruby-identifier">s1</span> = <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:UNIX</span>, <span class="ruby-value">:DGRAM</span>, <span class="ruby-value">0</span>)
<span class="ruby-identifier">s1_ai</span> = <span class="ruby-constant">Addrinfo</span>.<span class="ruby-identifier">unix</span>(<span class="ruby-string">&quot;/tmp/sock1&quot;</span>)
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">bind</span>(<span class="ruby-identifier">s1_ai</span>)

<span class="ruby-identifier">s2</span> = <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:UNIX</span>, <span class="ruby-value">:DGRAM</span>, <span class="ruby-value">0</span>)
<span class="ruby-identifier">s2_ai</span> = <span class="ruby-constant">Addrinfo</span>.<span class="ruby-identifier">unix</span>(<span class="ruby-string">&quot;/tmp/sock2&quot;</span>)
<span class="ruby-identifier">s2</span>.<span class="ruby-identifier">bind</span>(<span class="ruby-identifier">s2_ai</span>)
<span class="ruby-identifier">s3</span> = <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">for_fd</span>(<span class="ruby-identifier">s2</span>.<span class="ruby-identifier">fileno</span>)

<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">send</span> <span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-value">0</span>, <span class="ruby-identifier">s2_ai</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s3</span>.<span class="ruby-identifier">recvfrom</span>(<span class="ruby-value">10</span>) <span class="ruby-comment">#=&gt; [&quot;a&quot;, [&quot;AF_UNIX&quot;, &quot;/tmp/sock1&quot;]]</span>
</pre>

                              <div class="method-source-code" id="recvfrom-source">
            <pre>static VALUE
unix_recvfrom(int argc, VALUE *argv, VALUE sock)
{
    return rsock_s_recvfrom(sock, argc, argv, RECV_UNIX);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-send_io" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          send_io(io) &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends <em>io</em> as file descriptor passing.</p>

<pre class="ruby"><span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span> = <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">pair</span>

<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">send_io</span> <span class="ruby-constant">STDOUT</span>
<span class="ruby-identifier">stdout</span> = <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">recv_io</span>

<span class="ruby-identifier">p</span> <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">fileno</span> <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">fileno</span> <span class="ruby-comment">#=&gt; 6</span>

<span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;hello&quot;</span> <span class="ruby-comment"># outputs &quot;hello\n&quot; to standard output.</span>
</pre>

<p><em>io</em> may be any kind of IO object or integer file descriptor.</p>

                              <div class="method-source-code" id="send_io-source">
            <pre>static VALUE
unix_send_io(VALUE sock, VALUE val)
{
    int fd;
    rb_io_t *fptr;
    struct iomsg_arg arg;
    struct iovec vec[1];
    char buf[1];

#if FD_PASSING_BY_MSG_CONTROL
    union {
        struct cmsghdr hdr;
        char pad[sizeof(struct cmsghdr)+8+sizeof(int)+8];
    } cmsg;
#endif

    if (rb_obj_is_kind_of(val, rb_cIO)) {
        rb_io_t *valfptr;
        GetOpenFile(val, valfptr);
        fd = valfptr-&gt;fd;
    }
    else if (FIXNUM_P(val)) {
        fd = FIX2INT(val);
    }
    else {
        rb_raise(rb_eTypeError, &quot;neither IO nor file descriptor&quot;);
    }

    GetOpenFile(sock, fptr);

    arg.msg.msg_name = NULL;
    arg.msg.msg_namelen = 0;

    /* Linux and Solaris doesn&#39;t work if msg_iov is NULL. */
    buf[0] = &#39;\0&#39;;
    vec[0].iov_base = buf;
    vec[0].iov_len = 1;
    arg.msg.msg_iov = vec;
    arg.msg.msg_iovlen = 1;

#if FD_PASSING_BY_MSG_CONTROL
    arg.msg.msg_control = (caddr_t)&amp;cmsg;
    arg.msg.msg_controllen = (socklen_t)CMSG_LEN(sizeof(int));
    arg.msg.msg_flags = 0;
    MEMZERO((char*)&amp;cmsg, char, sizeof(cmsg));
    cmsg.hdr.cmsg_len = (socklen_t)CMSG_LEN(sizeof(int));
    cmsg.hdr.cmsg_level = SOL_SOCKET;
    cmsg.hdr.cmsg_type = SCM_RIGHTS;
    memcpy(CMSG_DATA(&amp;cmsg.hdr), &amp;fd, sizeof(int));
#else
    arg.msg.msg_accrights = (caddr_t)&amp;fd;
    arg.msg.msg_accrightslen = sizeof(fd);
#endif

    arg.fd = fptr-&gt;fd;
    while ((int)BLOCKING_REGION_FD(sendmsg_blocking, &amp;arg) == -1) {
        if (!rb_io_wait_writable(arg.fd))
            rsock_sys_fail_path(&quot;sendmsg(2)&quot;, fptr-&gt;pathv);
    }

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

